<?php
	$log = "";
	echo string::get_in_header_style("Allgemein");
	
	// Sites anzeigen
	$loginmanager = new loginmanager();
	$show_site = $loginmanager->allowed_is("Moderator", false);
	if($show_site)
	{
		$sql = "SELECT * FROM site";
		$column_headers = array("Titel", "GET-Variable", "Ab rang");
		$db_columns = array("title", "page", "rang");
		$site = new site($db_columns);
		if(isset($_POST["title"], $_POST["page"], $_POST["rang"])) {
			// Seite speichern
			if(isset($_POST["id"])) {
				if(is_numeric($_POST["id"])) {
					$site->save_site("site");
					$log = $site->log->get_log();
				}
			}
			// Neue Seite speichern
			if(isset($_POST["save_new"])) {
				$site->add_site("site");
				$log = $site->log->get_log();
			}
		}
		if(isset($_GET["action"], $_GET["id"])) {
			if(is_numeric($_GET["id"]) && $_GET["action"] == "delete") {
				$site->delete_site("site", "id", $_GET["id"]);
				$log = $site->log->get_log();
			}
		}
		echo string::get_in_header_style("Seiten");
		// Test site_mode-klasse
		$url = "index.php?page=allgemein";
		$array_new = array("title" => "", "page" => "", "rang" => "");
		$site->add_mode(new site_mode("new", "post", $url, "action", "save_new", "", "img/note_ok.png", "img/note_add.png", $array_new, "id"));
		$array_edit = array("title" => "title", "page" => "page", "rang" => "rang");
		$site->add_mode(new site_mode("edit", "post", $url, "action", "save_row", "", "img/note_ok.png", "img/note_edit.png", $array_edit, "id"));
		$array_show = array("title" => "title", "page" => "page", "rang" => "rang");
		$site->add_mode(new site_mode("show", "get", $url, "", "", "", "img/note_ok.png", "img/note_add.png", $array_show, "id"));
		$array_delete = array("title" => "title", "page" => "page", "rang" => "rang");
		// ende test 
		$mode_delete_img = "<img src=\"../img/note_delete.png\" width=\"16px\" height=\"16px\" />";
		$mode_delete_action = "index.php?page=allgemein&action=delete";
		$site->add_mode_delete(true, $mode_delete_img, $mode_delete_action);
		$site->set_attributes_for_table("class=\"user_table\" cellspacing=\"0px\" cellpadding=\"0px\"", "class=\"user_header_row\"", "class=\"tr_light\"", "class=\"tr_dark\"");
		echo $site->create_table($sql, true, true, $column_headers, "id");
		echo $log;
	}
?>